import { Component, OnInit, ViewChild } from '@angular/core';
import { SFComponent, SFDateWidgetSchema, SFSchema, SFUISchema } from '@delon/form';
import { NzMessageService } from 'ng-zorro-antd/message';
import { NzModalRef } from 'ng-zorro-antd/modal';
import { map } from 'rxjs/operators';
import { SystemService } from 'src/app/routes/sys-setting/services/system.service';
import { TicketService } from '../../../services/ticket.service';

@Component({
  selector: 'app-add-collection-invoice-modal',
  templateUrl: './add-collection-invoice-modal.component.html',
  styleUrls: ['./add-collection-invoice-modal.component.less']
})
export class AddCollectionInvoiceModalComponent implements OnInit {
  @ViewChild('sf', { static: false })
  sf!: SFComponent;
  i: any;
  schema!: SFSchema;
  constructor(private modal: NzModalRef, public msgSrv: NzMessageService, public service: TicketService) {}

  ngOnInit(): void {
    this.initSF();
  }
  initSF() {
    this.schema = {
      properties: {
        ltdId: {
          type: 'string',
          title: '网络货运人',
          ui: {
            widget: 'select',
            placeholder: '请选择',
            allowClear: true,
            asyncData: () => this.service.getNetworkFreightForwarder()
          },
          default: ''
        },
        ltd2Id: {
          type: 'string',
          title: '销售方',
          enum: [{ label: '全部', value: '全部' }],
          ui: {
            widget: 'select',
            placeholder: '请选择'
          },
          default: ''
        },
        ltd2I1d: {
          type: 'string',
          title: '收票类型',
          enum: [{ label: '全部', value: '全部' }],
          ui: {
            widget: 'select',
            placeholder: '请选择'
          },
          default: ''
        },
        createTime: {
          title: '发票日期',
          type: 'string',
          ui: {
            widget: 'date',
            format: 'yyyy-MM-dd',
            placeholder: '请选择',
            nzShowTime: true
          } as SFDateWidgetSchema
        },
        vatinvcode: {
          type: 'string',
          title: '发票号',
          ui: {
            placeholder: '请输入'
          }
        },
        vatinvc2ode: {
          type: 'string',
          title: '收票备注',
          ui: {
            placeholder: '请输入'
          }
        }
      },
      required: ['ltdId', 'ltd2Id', 'createTime', 'ltd2I1d', 'vatinvcode']
    };
  }

  sure() {
    const params: any = {
      ...this.sf?.value
    };
    // this.service.request(this.service.$api_add_staff, params).subscribe(res => {
    //   if (res) {
    //     this.service.msgSrv.success('保存成功！');
    //     this.modal.close(true);
    //   }
    // });
  }

  close() {
    this.modal.destroy();
  }
}
